<%--
  Created by IntelliJ IDEA.
  User: 64901
  Date: 2022/10/7
  Time: 21:05
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>注册公司</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link rel="stylesheet" href="${pageContext.request.contextPath}/static/layui/lib/layui-v2.6.3/css/layui.css" media="all">
    <link rel="stylesheet" href="${pageContext.request.contextPath}/static/layui/css/public.css" media="all">
</head>
<body>
<%-- 添加和修改窗口 --%>
<div>
    <form class="layui-form" style="width:90%;" id="dataFrm" lay-filter="dataFrm">
        <div class="layui-form-item">
            <label class="layui-form-label required">公司名称</label>
            <div class="layui-input-block">
                <input type="hidden" name="companyId" value="${companyDetail.companyId}">
                <input type="text" name="companyName" lay-verify="required" lay-reqtext="你公司名字还没写来" placeholder="请输入公司名字" value="${companyDetail.companyName}" class="layui-input">
            </div>
        </div>

        <div class="layui-form-item">
            <label class="layui-form-label required">公司照片</label>
            <div class="layui-input-block">
                <button type="button" class="layui-btn" id="test1">
                    <i class="layui-icon">&#xe67c;</i>修改图片
                </button>
            </div>

            <label class="layui-form-label">图片预览</label>
            <div class="layui-input-block" style="margin-top: 13px">
                <img src="${companyDetail.companyImg}" id="image" style="max-height: 150px">
            </div>
            <div class="layui-input-block" hidden>
                <input type="hidden" name="companyImg" lay-verify="required" lay-reqtext="你图片还没加来" id="companyImg" value="${companyDetail.companyImg}" class="layui-input">
            </div>
        </div>

        <div class="layui-form-item">
            <label class="layui-form-label required">公司详情</label>
            <div class="layui-input-block">
                <textarea name="companyDetail" class="layui-textarea" placeholder="公司详情" id="companyDetail">${companyDetail.companyDetail}</textarea>
            </div>
        </div>

        <div class="layui-form-item">
            <label class="layui-form-label">公司所在城市</label>
            <div class="layui-input-block">
                <input type="text" name="companyCity" lay-verify="required"  value="${companyDetail.companyCity}" class="layui-input">
            </div>
        </div>

        <div class="layui-form-item">
            <label class="layui-form-label required">公司行业</label>
            <div class="layui-input-block">
                <input type="text" name="companyIndustry" lay-verify="required" lay-reqtext="你公司行业还没写"  value="${companyDetail.companyIndustry}" class="layui-input">
            </div>
        </div>

        <div class="layui-form-item">
            <label class="layui-form-label">公司融资阶段</label>
            <div class="layui-input-block">
                <input type="text" name="companyFinance" lay-verify="required" lay-reqtext="你融资阶段还没写"  value="${companyDetail.companyFinance}" class="layui-input">
            </div>
        </div>

        <div class="layui-form-item layui-form-text">
            <label class="layui-form-label">公司规模</label>
            <div class="layui-input-block">
                <input type="text" name="companyScale" lay-verify="required" lay-reqtext="公司规模还没写" value="${companyDetail.companyScale}" class="layui-input">
            </div>
        </div>

        <div class="layui-form-item layui-form-text">
        <%--<label class="layui-form-label">状态</label>--%>
            <div class="layui-input-block">
                <input type="hidden" name="companyStatus" value="1" class="layui-input">
            </div>
        </div>

        <div class="layui-form-item layui-row layui-col-xs12">
            <div class="layui-input-block" style="text-align: center;">
                <button type="button" class="layui-btn" lay-submit lay-filter="doSubmit"><span
                        class="layui-icon layui-icon-add-1"></span>提交
                </button>
                <button type="reset" class="layui-btn layui-btn-warm"><span
                        class="layui-icon layui-icon-refresh-1"></span>重置
                </button>
            </div>
        </div>
    </form>
</div>
<script src="${pageContext.request.contextPath}/static/layui/lib/layui-v2.6.3/layui.js" charset="utf-8"></script>
<script>
    layui.use(['form','layer','upload'], function () {
        var $ = layui.jquery,
            form = layui.form,
            layer = layui.layer,
            upload = layui.upload;


        //上传图片
        let uploadInst = upload.render({
            elem: '#test1' //绑定元素
            ,url: '${pageContext.request.contextPath}/test/upload' //上传接口
            ,done: function(res){
                if (res.imgUrl != null){
                    layer.msg("上传成功");
                    //获得图片的路径
                    let src = res.imgUrl;
                    //将图片进行回显
                    $("#image").attr("src",src);
                    //将图片的地址赋值给 form的隐藏域
                    $("#companyImg").attr("value",src);
                }
            }
            ,error: function(){
                //请求异常回调
            }
        });
        var url = "${pageContext.request.contextPath}/backStageCompanyDetail/update";
        //监听表单提交事件
        form.on("submit(doSubmit)",function (data) {
            delete data.field.file;
            $.post(url,data.field,function(result){
                console.log(result)
                if(result.code === 20000){
                    //提示信息
                    layer.msg(result.msg,{icon: 1});
                }else {
                    layer.msg(result.msg);
                }
            },"json");

            //禁止页面刷新
            return false;
        });
    });
</script>
</body>
</html>
